package com.alignet.gn.util;

import java.util.Iterator;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

import com.alignet.gn.web.AccessBean;

public class UtilValidator {

    private static Validator validator;
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    
    public static Validator getValidators() {
    	ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
	    validator = factory.getValidator();
	    return validator;
    }
    public void getValidate(){
    	/*
    }
    	javax.validation.ValidatorFactory validatorFactory = javax.validation.Validation.buildDefaultValidatorFactory();
    		    javax.validation.Validator validator = validatorFactory.getValidator();
    		    SecUser user = new SecUser();
    		     
    		    java.util.Set<javax.validation.ConstraintViolation<SecUser>> validationErrors = validator.validate(user);
    		    if(validationErrors.isEmpty()) {
    		      System.out.println("Entidad valida.");
    		    } else {
    		    	System.out.println("Se presentaron errores al validar la entidad.");
    	      for(javax.validation.ConstraintViolation<SecUser> errors: validationErrors) {
    	    	  System.out.println(errors.getPropertyPath() + " - " + errors.getMessage());
    		      }    	
    		      */
    }
    
	public static void validateAccess(AccessBean access) {
		ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
	    validator = factory.getValidator();
        Set<ConstraintViolation<AccessBean>> constraintViolations = validator.validate(access);

        for (Iterator iterator = constraintViolations.iterator(); iterator.hasNext();) {
			ConstraintViolation<AccessBean> constraintViolation = (ConstraintViolation<AccessBean>) iterator.next();
			
		}
        
        Set<ConstraintViolation<AccessBean>> constraintViolations2 = validator.validateValue(AccessBean.class, "login", null);
        
	}
	
	
}
